<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <{include file="public/head" /}>
    <link rel="stylesheet" href="/static/css/admin_login.css">
</head>

<body>
<div class="login-box">
    <div class="layui-collapse box-div">
        <form class="layui-form" action="" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入用户名吗" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="margin-right: 1em;">密</span>码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" name="code" lay-verify="required" autocomplete="off" placeholder="请输入用户名吗" class="layui-input">
                </div>
                <div class="login-form-mid layui-word-aux">
                    <img src="<{:captcha_src()}>" class="verify-img" alt="看不清？点击刷新" onclick="this.src='<{:captcha_src()}>'">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>


<script src="/static/Plug-in/layui/layui.js"></script>
<script src="/static/jquery/jquery.min.js"></script>
<script type="text/javascript">
    layui.use(['element', 'layer', 'form'], function () {
        var layer = layui.layer,
            element = layui.element(), //导航的hover效果、二级菜单等功能，需要依赖element模块
            laydate = layui.laydate,
            form = layui.form(); //注入表单
//        console.log(form);

        //监听提交
        form.on('submit(formSubmit)', function (data) {
            var loading = layer.load();
            $.ajax({
                url: "<{:url('login/index')}>",
                type: "POST",
                data: $('form').serialize(),
                dataType: "json",
                success: function (data) {
                    layer.close(loading);
                    if (data.status == '1'){
                        layer.msg(data.msg, {
                            icon: 6,
                            time:1000
                        }, function () {
                            window.location.href = '<{:url("index/index")}>';
                        })
                    } else {
                        layer.msg(data.msg, {
                            icon: 5
                        }, function () {
                            $("input[name='code']").val('');
                            $('.verify-img').trigger('click');
                        })
                    }
                },
                error: function (res) {
                    layer.msg(res, {
                        icon: 5
                    }, function () {
                        $("input[name='code']").val('');
                        $('.verify-img').trigger('click');
                    })
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
